class SocketIo {
	private static _instance: SocketIo;
	public static getInstance(): SocketIo {
		if (!SocketIo._instance) {
			SocketIo._instance = new SocketIo();
		}
		return SocketIo._instance;
	}

	public socket: SocketIOClient.Socket;
	public constructor() {
		// this.socket = io.connect('http://localhost:3101/');
		this.socket = io.connect('http://144.34.173.53:3101/');
		
	}

	public request(msg: string, data?: any): void {
		this.socket.emit(msg, data);
	}

	public addEvent(event: string, fn: Function, thisObj?: any): void {
		this.socket.on(event, function (data) {
			// fn.apply(thisObj, data);
			App.event.dispatchEventWith(event, false, data);
		});
	}

	public removeEvent(event: string, fn: Function, thisObj?: any): void {
		this.socket.off(event, function () {
			fn.apply(thisObj);
		});
	}
}